import 'package:flutter/material.dart';

import 'package:junyeyishu/utils/utils.dart';
import 'package:junyeyishu/widgets/QGWidget.dart';

class QGMineOrderCell extends StatefulWidget {
  dynamic data;
  QGMineOrderCell({super.key, this.data});
  @override
  State<QGMineOrderCell> createState() => QGMineOrderCellState();
}

class QGMineOrderCellState extends State<QGMineOrderCell> {
  @override
  Widget build(BuildContext context) {
    var num = widget.data?["goods_num"] ?? widget.data?["good_num"];

    if (num is String) {
      num = "购买数量：$num";
    } else {
      num = "#${widget.data?["nft_no"]}/${widget.data?["total"]}";
    }

    return Container(
      margin: EdgeInsets.only(top: 10.rpx, left: 10.rpx, right: 10.rpx),
      padding: EdgeInsets.all(10.rpx),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(6.rpx),
        color: Color(0xFFFFFFFF),
      ),
      child: Column(children: [
        Row(
          children: [
            ClipRRect(
              borderRadius: BorderRadius.circular(4.rpx),
              child: QGImage(
                  url: widget.data?["thumb_img"],
                  width: 52.rpx,
                  height: 52.rpx),
            ),
            SizedBox(width: 10.rpx),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Expanded(
                        child: Text(
                          widget.data?["order_name"] ?? "",
                          style: TextStyle(
                              color: Color(0xFF111111),
                              fontSize: 14.rpx,
                              fontWeight: FontWeight.normal),
                        ),
                      ),
                      Text(
                        '￥${widget.data?["total_fee"] ?? widget.data?["price"]}',
                        style: TextStyle(
                            color: Color(0xFF111111),
                            fontSize: 14.rpx,
                            fontWeight: FontWeight.bold),
                      ),
                    ],
                  ),
                  SizedBox(height: 13.rpx),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        num,
                        style: TextStyle(
                            color: const Color(0xff999999),
                            fontSize: 12.rpx,
                            fontWeight: FontWeight.normal),
                      ),
                      Flexible(
                        child: Text(
                          widget.data?["created"] ?? "",
                          style: TextStyle(
                              color: const Color(0xff999999),
                              fontSize: 12.rpx,
                              fontWeight: FontWeight.normal),
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
        SizedBox(height: 10.rpx),
        Container(height: 0.5.rpx, color: Color(0xFFEAEAEA)),
        SizedBox(height: 10.rpx),
        buildState(),
      ]),
    );
  }

  buildState() {
    var img;
    Widget text = Container();
    switch (widget.data?["type"]) {
      case 0:
        img = "mine_order_success";
        text = Text(
          '已支付',
          style: TextStyle(
              color: const Color(0xFF07C160),
              fontSize: 12.rpx,
              fontWeight: FontWeight.normal),
        );

        break;
      case 1:
        img = "mine_order_waiting";
        text = Text(
          '待支付',
          style: TextStyle(
              color: const Color(0xFFFF3838),
              fontSize: 12.rpx,
              fontWeight: FontWeight.normal),
        );
        break;
      case 2:
        img = "mine_order_cancel";
        text = Text(
          '已取消',
          style: TextStyle(
              color: const Color(0xff999999),
              fontSize: 12.rpx,
              fontWeight: FontWeight.normal),
        );
        break;
    }

    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Container(
          padding: EdgeInsets.symmetric(horizontal: 7.rpx, vertical: 3.rpx),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(4.rpx),
            color: Color(0xFFF8F8F6),
          ),
          child: Row(
            children: [
              QGImage(asset: img),
              SizedBox(width: 6.rpx),
              text,

              // Text(
              //   '等待付款',
              //   style: TextStyle(
              //       color: const Color(0xffE61212),
              //       fontSize: 11.rpx,
              //       fontWeight: FontWeight.normal),
              // ),
              // SizedBox(width: 8.rpx),
              // Text(
              //   '00:05:00',
              //   style: TextStyle(
              //       color: const Color(0xffffffff),
              //       fontSize: 12.rpx,
              //       fontWeight: FontWeight.normal),
              // ),
            ],
          ),
        ),
        widget.data?["type"] == 1
            ? QGImage(asset: "mine_info_arrow")
            : Container(),
      ],
    );
  }
}
